public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int x = 0, y = n - 1;
        while(x < m && y >= 0){
            if(target > matrix[x][y]){
                x++;
            } else if(target < matrix[x][y]){
                y--;
            } else {
                return true;
            }
        }


        return false;
    }
}
